#region Using

using System;

using Gizmox.WebGUI.Forms;
using PLACEHR.Web.Utilities;

#endregion

namespace PLACEHR.Web.Categories.Business.Forms
{
    public partial class ChangePassword : Form
    {
        private Employee currItem;
        public ChangePassword()
        {
            InitializeComponent();
            currItem = Global.CurrentUser;
            InitialData();
        }
        private void InitialData()
        {
            lblOldPassword.Text = LanLayer.GetTrans(196);
            lblNewPassword.Text = LanLayer.GetTrans(197);
            lblPasswordOnceMore.Text = LanLayer.GetTrans(198);
            btnSave.Text = LanLayer.GetTrans(18);
            btnCancel.Text = LanLayer.GetTrans(19);
            this.Text = LanLayer.GetTrans(202);
        }
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(tbxOldPassword.Text.Trim()) 
                || string.IsNullOrWhiteSpace(tbxNewPassword.Text.Trim()) 
                || string.IsNullOrWhiteSpace(tbxPasswordOnceMore.Text.Trim()))
            {
                MessageBox.Show(LanLayer.GetTrans(199));
                return;
            }

            if (!string.Equals(currItem.Password, tbxOldPassword.Text.Trim()))
            {
                MessageBox.Show(LanLayer.GetTrans(200));
                return;
            }

            if (!string.Equals(tbxNewPassword.Text.Trim(), tbxPasswordOnceMore.Text.Trim()))
            {
                MessageBox.Show(LanLayer.GetTrans(201));
                return;
            }

            currItem.Password = tbxNewPassword.Text.Trim();
                       
            Global.Context.SaveChanges();
            Close();
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            Close();
        }
    }
}